package util;

import java.awt.Shape;

public enum RenderingActions implements Action {

	DRAW {
		@Override
		public void performAction (Object param) {
			if (param instanceof Object[]) {
				Object[] params = (Object[]) param;
				if (params.length == 2 && params[0] instanceof DynamicImage) {
					DynamicImage image = (DynamicImage) params[0];
					synchronized (params[1]) {
						if (params[1] instanceof Shape) {
							image.getGraphics().draw((Shape) params[1]);
						} else if (params[1] instanceof ImageWrapper) {
							ImageWrapper wrapper = (ImageWrapper) params[1];
							synchronized (wrapper.getImage()) {
								image.getGraphics().drawImage(wrapper.getImage(), wrapper.getX(), wrapper.getY(), wrapper.getWidth(), wrapper.getHeight(), null);
							}
						}
					}
				}
			}
		}
	},

	FILL {
		@Override
		public void performAction (Object param) {
			if (param instanceof Object[]) {
				Object[] params = (Object[]) param;
				if (params.length == 2 && params[0] instanceof DynamicImage && params[1] instanceof Shape) {
					DynamicImage image = (DynamicImage) params[0];
					synchronized (params[1]) {
						image.getGraphics().fill((Shape) params[1]);
					}
				}
			}
		}
	}

}
